package com.chat.http.validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.chat.vo.params.OnlinePeopleVo;

/**
 * 针对OnlinePeopleVo类的校验器
 * 
 * @author lwh
 *
 */
@Component
public class OnlinePeopleVoValidator implements Validator {

	@Override
	public boolean supports(Class<?> clazz) {
		return OnlinePeopleVo.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
	}

	/**
	 * PlanConnectionController的planConn方法，准备连接前参数校验
	 * @param target
	 * @param errors
	 */
	public void planConnValidate(String accesskey, String secretkey, Object target, Errors errors) {
		
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName", "账号为空");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "token", "token为空");
		
		if( accesskey == null || accesskey.trim().equals("") || secretkey == null || secretkey.trim().equals("") ){
			errors.reject("凭证错误");
		}
	}
}
